const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
const copyWebpackPlugin = require('copy-webpack-plugin')


module.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    plugins: [
        new htmlWebpackPlugin({
            // template: 'html-withimg-loader!' + path.join(__dirname, './src/index.html'),
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html'
        }),
        //将文件拷贝到编译目录下，可解决html文件中的img script audio 标签中的 src 404 问题
        new copyWebpackPlugin([
            {
                from : path.join(__dirname, '/src/static'),
                to : path.join(__dirname + '/dist/static')
            }
        ])
    ],
    module: {
        rules: [{
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.(jpg|jpeg|png|gif|bmp)$/,
                //设置打包后的文件目录名images/
                use: 'url-loader?limit=4096&name=images/[hash:8][name].[ext]'
            },
            {
                test: /\.(woff|woff2|svg|eot|ttf)/,
                use: 'url-loader'
            },
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: require.resolve('zepto'),
                use: ['exports-loader?window.Zepto', 'script-loader']
            },
            {
                test: /\.exec.js$/,
                use: 'script-loader'
            },
            // {
            //     test: /\.(htm|html)$/,
            //     use: 'html-withimg-loader',
            // }
        ]
    }

}